/**
 * 文件挂接api
 */
import request from '@/utils/request'



/**
 *  查看树结构模板
 * @param {*} obj 
 * @returns 
 */
export function initTemplateTree(obj = { way: 1 }) {

  obj = Object.assign({}, obj)
  obj['staffid'] = localStorage.getItem("_staffid")
  var valueObj = new Object();
  valueObj.valueMap = obj


  var params = encodeURIComponent(JSON.stringify(valueObj));
  //console.log(params)
  // return request({
  //   url: '/request/arcService/initTemplateTree.jspx',
  //   method: 'post',
  //   data: { remote_args: params },
  //   json: true,

  // })

  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    url: `/request/arcService/initTemplateTree.jspx`,
    method: 'post',
    dataType: "json",
    data: { remote_args: params }
  })

}

/**
 * 查看当前版本是否为网络本
 * @returns 
 */
export function queryNetwork() {
  return call('paramsService', 'queryNetworkVersion', {});
}


/**
 *  查询后台mobilequery
 * @param {*} _typeid  
 * @param {*} paramObj 
 * @returns 
 */
export function mobileQuery(_typeid, _pageIndex, _pageSize, paramObj = {}) {
  paramObj = Object.assign({}, paramObj)
  paramObj['staffid'] = localStorage.getItem("_staffid")
  var valueObj = new Object();
  valueObj.currentPage = _pageIndex;
  valueObj.pageSize = _pageSize;
  valueObj.valueMap = paramObj
  var params = encodeURIComponent(JSON.stringify(valueObj));
  // console.log(params)
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    url: `/mobilequery/${_typeid}.jspx`,
    method: 'post',
    dataType: "json",
    data: { remote_args: params }
  })
}

/**
 * GET 查询数据
 * @param {*} _typeId id 
 * @param {*} _pageIndex 
 * @param {*} _pageSize 
 * @param {*} _sortExpr 
 * @param {*} paramObj 
 * @returns 
 */
export function query(_typeId, _pageIndex, _pageSize, _sortExpr, paramObj = {}) {
  paramObj = Object.assign({}, paramObj)
  paramObj['staffid'] = localStorage.getItem("_staffid")
  var valueObj = new Object();
  valueObj.currentPage = _pageIndex;
  valueObj.pageSize = _pageSize;
  valueObj.sortExpr = _sortExpr;
  valueObj.valueMap = paramObj


  var params = encodeURIComponent(JSON.stringify(valueObj));
  //console.log(params)
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    url: `/query/${_typeId}/save.jspx`,
    method: 'get',
    dataType: "json",
    data: { remote_args: params }
  })
}


/**
 * GET 获取数据
 * @param {*} _service 
 * @param {*} _method 
 * @param {*} paramObj 
 * @returns 
 */
export function call(_service, _method, paramObj = {}) {
  paramObj = Object.assign({}, paramObj)
  paramObj['staffid'] = localStorage.getItem("_staffid")
  var valueObj = new Object();
  valueObj.valueMap = paramObj
  var params = encodeURIComponent(JSON.stringify(valueObj));
  //console.log(params)
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    url: `/request/${_service}/${_method}.jspx`,
    method: 'post',
    dataType: "json",
    data: { remote_args: params }
  })
}

/**
 * Post 开始事务-提交数据
 * @param {*} _service 
 * @param {*} _method 
 * @param {*} paramObj 
 * @returns 
 */
export function callTrans(_service, _method, paramObj = {}) {
  paramObj = Object.assign({}, paramObj)
  paramObj['staffid'] = localStorage.getItem("_staffid")
  var valueObj = new Object();
  valueObj.valueMap = paramObj
  var params = encodeURIComponent(JSON.stringify(valueObj));
  // console.log(params)
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    url: `/trans/${_service}/${_method}.jspx`,
    method: 'post',
    dataType: "json",
    data: { remote_args: params }
  })
}



/**
 * Post 开始事务-提交数据
 * @param {*} _service 
 * @param {*} _method 
 * @param {*} paramObj 
 * @returns 
 */
export  function callTransAsync(_service, _method, paramObj = {}) {

  paramObj = Object.assign({}, paramObj)
  paramObj['staffid'] = localStorage.getItem("_staffid")
  var valueObj = new Object();
  valueObj.valueMap = paramObj
  var params = encodeURIComponent(JSON.stringify(valueObj));
  // console.log(params)
  return  request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    url: `/trans/${_service}/${_method}.jspx`,
    method: 'post',
    dataType: "json",
    data: { remote_args: params }
  })
}



/**
 * 判断是否为空
 * @param value 判断字符串
 * @returns {boolean} true/false
 */
export function isBlank(value) {
  if (value == "undefined" || value == undefined) {
    return true;
  }
  return !value || !/\S/.test(value)
}

/**
* 判断不为空
* @param value 判断字符串
* @returns {boolean} true/false
*/
export function notBlank(value) {

  if (value == "undefined" || value == undefined) {
    return false;
  }
  if (typeof (value) == 'number') {
    return value.length == 0 ? false : true;
  }

  if (typeof (value) == 'string') {
    return value.trim().length == 0 ? false : true;
  }
}

/**
 *  处理ftp路径
 * @param {*} temppath 原始路径
 * @param {*} remotePath ftp路径
 * @returns 
 */
export function handleUrl(temppath, remotePath) {

  return (temppath.substring(temppath.lastIndexOf(remotePath) + remotePath.length, temppath.length)).replace("\\\\", "/").replace("\\", "/");;

}

